<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "article_class".
 *
 * @property integer $article_class_id
 * @property string $article_class_name
 * @property integer $parent_id
 * @property integer $sort
 * @property integer $is_show
 *
 * @property ArticleClass $parent
 * @property ArticleClass[] $articleClasses
 */
class ArticleClass extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'article_class';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['article_class_name'], 'required'],
            [['parent_id', 'sort', 'is_show'], 'integer'],
            [['article_class_name'], 'string', 'max' => 50],
            [['parent_id'], 'exist', 'skipOnError' => true, 'targetClass' => ArticleClass::className(), 'targetAttribute' => ['parent_id' => 'article_class_id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'article_class_id' => '文章分类ID',
            'article_class_name' => '文章分类名',
            'parent_id' => '父分类ID',
            'sort' => '排序，默认50，越大越靠前',
            'is_show' => '是否显示',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getParent()
    {
        return $this->hasOne(ArticleClass::className(), ['article_class_id' => 'parent_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getArticleClasses()
    {
        return $this->hasMany(ArticleClass::className(), ['parent_id' => 'article_class_id']);
    }
}
